{config_load 'layout.conf' 'site_information'}
{foreach $conf->values['content.def']['site_information'] as $def}
	{if ($def|contains:"|")}
		{assign var="indexOfPipe" 		value=$def|strpos:"|"}		
		{assign var="valuestr" 			value=$def|substr:($indexOfPipe+1)}			
		
		{assign var="values" value=","|explode:$valuestr}
		{assign var="labelkey" value=$def|substr:0:$indexOfPipe}
		
	
		<label for="site_information_{$labelkey}">{#$labelkey#|default:$labelkey}</label>
		<select id="site_information_{$labelkey}" name="site_information_{$labelkey}">
			{html_options values=$values output=$values selected=$site[$labelkey]|default:""}
		</select><br/>
	{else}
	<label for="meta_{$def}">{#$def#|default:$def}</label>
	<input type="text" name="site_information_{$def}" id="site_information_{$def}" 
		value="{$site[$def]|default:""}"><br/>
	{/if}
{/foreach}

<style>
#pagesmg ul{
	list-style-type: none;
}
#pagesmg span{
	display: block;
}
#pagesmg ul { list-style-type: none; margin: 0; padding: 0; }
#pagesmg li.root ul { margin-left: 15px; }
#pagesmg li { margin: 5px; }
#pagesmg li.root { width: 100%; background-image: none;}
#pagesmg input { margin: 0 4px; }
#pagesmg .up, #pagesmg .down{ display: block;}

</style>

<div id="pagesmg">
	<ul>
		<li class="tree_item ui-state-default root">
			<span>Racine</span>
			<ul id="racine">{include file="def.sub_menu.tpl"}</ul> 
		</li>
	</ul>
</div>
<div id="pagesmg_parent">

</div>

<div style="clear: both"></div>

<script type="text/javascript">
	{literal}	
	function site_information_open(){
		$("li.tree_item span").droppable({
			tolerance        : "pointer",
			hoverClass        : "ui-state-highlight",
			drop            : function(event, ui){
				var dropped = ui.draggable;
				dropped.css({top: 0, left: 0});
				var me = $(this).parent();
				if(me == dropped)
					return;
				var subbranch = $(me).children("ul");
				if(subbranch.size() == 0) {
					me.find("span").after("<ul></ul>");
					subbranch = me.find("ul");
				}
				var oldParent = dropped.parent();
				subbranch.eq(0).append(dropped);
				var oldBranches = $("li", oldParent);
				if (oldBranches.size() == 0) { $(oldParent).remove(); }
			}
		});
		
		$("li.tree_item").draggable({
			opacity: 0.5,
			revert: true
		});
				
		$("#pagesmg .up").click(function(){
			var me = $(this).parent().parent().parent();
			$(me).insertBefore($(me).prev());
			$(me).effect("highlight");
		});
			
		$("#pagesmg .down").click(function(){
			var me = $(this).parent().parent().parent();
			$(me).insertAfter($(me).next());
			$(me).effect("highlight");
		});
	
	}
	function site_information_validate(){
		$("#pagesmg_parent").html('');
		parseTree($("#racine"), '');
		return true;
	}
	function site_information_close(){
		return true;
	}
	
	function parseTree(ul, parent){
		ul.children("li").each(function(){
			var subtree = $(this).children("ul");
			var childpagevalue = $(this).find("input").first().attr('value');
			$("#pagesmg_parent").append('<input type="hidden" name="pagesmg_'+$(this).attr('id')+'" value="'+childpagevalue+'"/>');
			$("#pagesmg_parent").append('<input type="hidden" name="pagesmg_'+childpagevalue+'_parent" value="'+parent+'"/>');
			$("#pagesmg_parent").append("<br/>");
			if(subtree.children().size() > 0){
				return parseTree(subtree, childpagevalue);
			}
		});
	}

	{/literal}
</script>